<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link href="assets/css/bootstrap.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="assets/css/font-awesome.min.css" />
		<!--[if IE 7]>
		  <link rel="stylesheet" href="assets/css/font-awesome-ie7.min.css" />
		<![endif]-->
		<link rel="stylesheet" href="assets/css/ace.min.css" />
		<link rel="stylesheet" href="assets/css/ace-rtl.min.css" />
		<link rel="stylesheet" href="assets/css/ace-skins.min.css" />
        <link rel="stylesheet" href="css/style.css"/>
		<!--[if lte IE 8]>
		  <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
		<![endif]-->
		<script src="assets/js/ace-extra.min.js"></script>
		<!--[if lt IE 9]>
		<script src="assets/js/html5shiv.js"></script>
		<script src="assets/js/respond.min.js"></script>
		<![endif]-->
		<script src="js/jquery-1.9.1.min.js"></script>        
        <script src="assets/layer/layer.js" type="text/javascript"></script>
<title>后端登录</title>
</head>

<body class="login-layout Reg_log_style">
<div class="logintop">    
    <span>欢迎后台管理界面平台</span>    
    <ul>
    <li><a href="#">返回首页</a></li>
    <li><a href="#">帮助</a></li>
    <li><a href="#">关于</a></li>
    </ul>    
    </div>
    <div class="loginbody">
<div class="login-container">
	<div class="center">
<!--	     <img src="images/logo1.png" />-->
							</div>

							<div class="space-6"></div>
							<div class="position-relative">
								<div id="login-box" class="login-box widget-box no-border visible">
									<div class="widget-body">
										<div class="widget-main">
											<h4 class="header blue lighter bigger">
												<i class="icon-coffee green"></i>
												后台登录
											</h4>

											<div class="login_icon"><img src="images/login.png" width="140px" height="160px" style="position: relative;top: 20px"/></div>

											<form class="">
												<fieldset>
										<ul>
   <li class="frame_style form_error"><label class="user_icon"></label><input name="用户名" type="text"  id="username" placeholder="请输入用户名"/></li>
   <li class="frame_style form_error"><label class="password_icon"></label><input name="密码" type="password"   id="userpwd" placeholder="请输入密码"/></li>
   <li class="frame_style form_error"><label class="Codes_icon"></label><input name="验证码" type="text"   id="Codes_text" placeholder="请输入验证码"/>
	   <div class="Codes_region"> <a
			   class="btn" href="javascript:void(0);"
			   id="sendMobileCode" style="width: 80px;height: 35px;">
		   <img style="position: absolute;right:-5px;bottom: -5px; width: 80px; height: 35px;"
				src="http://localhost:8080/SnacksShop/manager.do?type=backCode" id="backCodeImg" alt="验证码未加载">
	   </a></div></li>
  </ul>
													<div class="space"></div>

													<div class="clearfix">
														<label class="inline" style="margin-top: 7px">
															<input type="checkbox" class="ace">
															<span class="lbl">保存密码</span>
														</label>
														<button type="button" class="width-35 pull-right btn btn-sm btn-primary" id="login_btn" >
															<i class="icon-key"></i>
															登录
														</button>
													</div>

													<div class="space-4"></div>
												</fieldset>
											</form>

											<div class="social-or-login center">
												<span class="bigger-110">通知</span>
											</div>

											<div class="social-login center">
											本网站系统不再对IE8以下浏览器支持，请见谅。
											</div>
										</div><!-- /widget-main -->

										<div class="toolbar clearfix">
											

											
										</div>
									</div><!-- /widget-body -->
								</div><!-- /login-box -->
							</div><!-- /position-relative -->
						</div>
                        </div>
                        <div style="position: absolute;left:50%;margin-left:150px;top:160px"><a href="register.html">商家免费注册</a></div>
                        <div style="position: absolute;left:50%;margin-left:10px;top:404px ;">
							<select  id="selectType" style="width: 100px;height: 27px;">
								<option>商家</option>
								<option>管理员</option>
								<option>超级管理员</option>
							</select>
						</div>
                        <div class="loginbm">版权所有  2021  <a href="">卓景京信息技术有限公司</a> </div><strong></strong>
</body>
<script>
	$('#login_btn').on('click', function() {
		// var num=0;
		// var str="";
		// $("input[type$='text'],input[type$='password']").each(function(n){
		// 	if($(this).val()=="")
		// 	{
		//
		// 		layer.alert(str+=""+$(this).attr("name")+"不能为空！\r\n",{
		// 			title: '提示框',
		// 			icon:0,
		// 		});
		// 		num++;
		// 		return false;
		// 	}
		// });

		var backName = $("#username").val();
		var backPassWord = $("#userpwd").val();
		var backCode = $("#Codes_text").val();
		var loginType=$("#selectType").val();
		if (loginType=="商家"){
			loginType=2;
		}else if (loginType=="管理员"){
			loginType=0;
		}else if (loginType=="超级管理员"){
			loginType=1;
		}
		if (backName == "" || backName == null) {
			layer.msg('用户名不能为空!', {icon: 1, time: 1500});
			return;
		}
		if (backPassWord == "" || backPassWord == null) {
			layer.msg('密码不能为空!', {icon: 1, time: 1500});
			return;
		}
		if (backCode == "" || backCode == null) {
			layer.msg('验证码不能为空!', {icon: 1, time: 1500});
			return;
		}
		if (loginType==2){
			console.log("商家");
			$.ajax({
				url: "http://localhost:8080/SnacksShop/boss.do?type=shopLogin",
				data: {
					backName: backName,
					backPassWord: backPassWord,
					backCode: backCode,
					loginType:loginType
				},
				crossDomain: true,
				xhrFields: {
					withCredentials: true
				},
				type: "post",
				success: function (data) {
					if (data == "codeError") {
						layer.msg('验证码错误!', {icon: 1, time: 1500});
						$("#BackCode").val("");
						document.getElementById("backCodeImg").setAttribute("src", "http://localhost:8080/SnacksShop/manager.do?type=backCode&amp;" + new Date().getTime());
					}
					if (data == "userError") {
						layer.msg("用户名或密码错误", {icon: 1, time: 1500});
						$("#BackCode").val("");
						$("#backPassWord").val("");
						document.getElementById("backCodeImg").setAttribute("src", "http://localhost:8080/SnacksShop/manager.do?type=backCode&amp;" + new Date().getTime());
					}
					if (data == "true") {
						layer.msg("登录成功", {icon: 1, time: 1500});
						setTimeout(function (){
							location.href = "./index.html?id=2";
						},1500);
					}
				},
				error: function (data) {
					layer.msg('请检查你的网络!', {icon: 1, time: 1500});
				}
			})
		}
		if (loginType==0){
			console.log("管理员");
			$.ajax({
				url: "http://localhost:8080/SnacksShop/manager.do?type=managerLogin",
				data: {
					backName: backName,
					backPassWord: backPassWord,
					backCode: backCode,
					loginType:loginType
				},
				crossDomain: true,
				xhrFields: {
					withCredentials: true
				},
				type: "post",
				success: function (data) {
					if (data == "codeError") {
						layer.msg('验证码错误!', {icon: 1, time: 1500});
						$("#BackCode").val("");
						document.getElementById("backCodeImg").setAttribute("src", "http://localhost:8080/SnacksShop/manager.do?type=backCode&amp;" + new Date().getTime());
					}
					if (data == "userError") {
						layer.msg("用户名或密码错误", {icon: 1, time: 1500});
						$("#BackCode").val("");
						$("#backPassWord").val("");
						document.getElementById("backCodeImg").setAttribute("src", "http://localhost:8080/SnacksShop/manager.do?type=backCode&amp;" + new Date().getTime());
					}
					if (data == "true") {
						layer.msg("登录成功", {icon: 1, time: 1500});
						setTimeout(function (){
							location.href = "./index.html?id=0";
						},1500);
					}
				},
				error: function (data) {
					layer.msg('请检查你的网络!', {icon: 1, time: 1500});
				}
			})
		}
		if (loginType==1){
			console.log("超级管理员");
			$.ajax({
				url: "http://localhost:8080/SnacksShop/supManager.do?type=login",
				data: {
					backName: backName,
					backPassWord: backPassWord,
					backCode: backCode,
					loginType:loginType
				},
				crossDomain: true,
				xhrFields: {
					withCredentials: true
				},
				type: "post",
				success: function (data) {
					if (data == "codeError") {
						layer.msg('验证码错误!', {icon: 1, time: 1500});
						$("#BackCode").val("");
						document.getElementById("backCodeImg").setAttribute("src", "http://localhost:8080/SnacksShop/manager.do?type=backCode&amp;" + new Date().getTime());
					}
					if (data == "userError") {
						layer.msg("用户名或密码错误", {icon: 1, time: 1500});
						$("#BackCode").val("");
						$("#backPassWord").val("");
						document.getElementById("backCodeImg").setAttribute("src", "http://localhost:8080/SnacksShop/manager.do?type=backCode&amp;" + new Date().getTime());
					}
					if (data == "true") {
						layer.msg("登录成功", {icon: 1, time: 1500});
						setTimeout(function (){
							location.href = "./index.html?id=1";
						},1500);
					}
				},
				error: function (data) {
					layer.msg('请检查你的网络!', {icon: 1, time: 1500});
				}
			})
		}
	})

		//验证码刷新
		$("#backCodeImg").click("click", function () {
			document.getElementById("backCodeImg").setAttribute("src", "http://localhost:8080/SnacksShop/manager.do?type=backCode&amp;" + new Date().getTime());
		})
		// if(num>0){  return false;}
		// else{
		// 	// layer.alert('登录成功！',{
		// 	// 	title: '提示框',
		// 	// 	icon:1,
		// 	// });
		// 	layer.msg("登录成功",{icon: 1, time: 1500});
		// 	location.href="index.html";
		// 	// layer.close(index);
		// }
	// });
	// $(document).ready(function(){
	// 	$("input[type='text'],input[type='password']").blur(function(){
	// 		var $el = $(this);
	// 		var $parent = $el.parent();
	// 		$parent.attr('class','frame_style').removeClass(' form_error');
	// 		if($el.val()==''){
	// 			$parent.attr('class','frame_style').addClass(' form_error');
	// 		}
	// 	});
	// 	$("input[type='text'],input[type='password']").focus(function(){
	// 		var $el = $(this);
	// 		var $parent = $el.parent();
	// 		$parent.attr('class','frame_style').removeClass(' form_errors');
	// 		if($el.val()==''){
	// 			$parent.attr('class','frame_style').addClass(' form_errors');
	// 		} else{
	// 			$parent.attr('class','frame_style').removeClass(' form_errors');
	// 		}
	// 	});

</script>
</html>
